package
{

import flash.display.MovieClip;
import flash.events.Event;
import flash.geom.Vector3D;

public class Gugit extends MovieClip
{
	private var frameCount:Number = 0;
	private var frameVariance:Number = 1;
	private var previousPosition:Vector3D = new Vector3D(0,0,0,0);
	
	private var gameState:GameState = new GameState();
	
	private var scoreBoard = new ScoreBoard();
	private var deathCount = new DeathCount(gameState);

	
	public function Gugit():void
	{
		addEventListener(Event.ENTER_FRAME, createGug);
		addChild(scoreBoard);
		addChild(deathCount);
	}

	public function createGug(evt:Event = null):void
	{
		if (frameCount++ % int(180 * frameVariance) == 0 && gameState.State != GameState.GAME_OVER_STATE)
		{
			trace("gamestate: " + gameState.State);
			var newGug:Gug = new Gug(scoreBoard,deathCount);
			addChild(newGug);
			var newX:Number = Math.random() * (this.stage.stageWidth - newGug.width) + (newGug.width / 2);
			var newY:Number = Math.random() * (this. stage.stageHeight - newGug.height - 100) + (newGug.height / 2) + 100;
			
			while(Math.abs(newX - previousPosition.x) < 90)
				newX = Math.random() * (this.stage.stageWidth - newGug.width) + (newGug.width / 2);
			while(Math.abs(newY - previousPosition.y) < 100)
				newY = Math.random() * (this. stage.stageHeight - newGug.height) + (newGug.height / 2);
			
			previousPosition.x = newGug.x;
			previousPosition.y = newGug.y;
			newGug.x = newX;
			newGug.y = newY;
			
			//trace(newGug.height + " " + newGug.width);
			//trace("stage: (" + stage.stageWidth + "," + this.stage.stageHeight + ") x: " + newGug.x + ", y: " + newGug.y);
		}
	}
}

}